﻿using KELT.KELTObjects.ViewportObjectModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace KELT.AutoColor
{
    /// <summary>
    /// AutoColorWindow.xaml에 대한 상호 작용 논리
    /// </summary>
    public partial class AutoColorWindow : Window
    {
        private TOOL mainToolContext;
        private ColorBoxManager colorBoxManager;
        public AutoColorWindow(TOOL tool)
        {
            InitializeComponent();
            this.mainToolContext = tool;
            Init();

        }

        public void Init()
        {
            colorBoxManager = new ColorBoxManager(this, ColorListStackPanel);
        }

        private void redSliderChange(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            RedTextBox.Text = "" + (int)e.NewValue;
            if(isChangeAnimation)
                colorBoxManager.setColor();
        }
        private void greenSliderChange(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            GreenTextBox.Text = "" + (int)e.NewValue;
            if (isChangeAnimation)
                colorBoxManager.setColor();

        }
        private void blueSliderChange(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            BlueTextBox.Text = "" + (int)e.NewValue;
            if (isChangeAnimation)
                colorBoxManager.setColor();

        }

        bool isChangeAnimation = true;
        private void selectColor1Down(object sender, MouseButtonEventArgs e)
        {
            isChangeAnimation = false;
            colorBoxManager.setSliderSelectColor(0);
            isChangeAnimation = true;
        }

        private void selectColor2Down(object sender, MouseButtonEventArgs e)
        {
            isChangeAnimation = false;
            colorBoxManager.setSliderSelectColor(1);
            isChangeAnimation = true;

        }
        private void selectColor3Down(object sender, MouseButtonEventArgs e)
        {
            isChangeAnimation = false;
            colorBoxManager.setSliderSelectColor(2);
            isChangeAnimation = true;

        }
        private void selectColor4Down(object sender, MouseButtonEventArgs e)
        {
            colorBoxManager.setSliderSelectColor(3);

        }
        private void selectColor5Down(object sender, MouseButtonEventArgs e)
        {
            colorBoxManager.setSliderSelectColor(4);

        }


        private void click_Ok(object sender, RoutedEventArgs e)
        {
            Random rand = new Random();
            int backNum = rand.Next(5);
            Color Backcolor = colorBoxManager.selectItem.colors[backNum];
            mainToolContext.background.Fill = new SolidColorBrush(Backcolor);

            mainToolContext.cameraManager.pageList.ElementAt(mainToolContext.cameraManager.pageList.Count - 1).nowBackgroundColor = Backcolor;
            mainToolContext.cameraManager.pageList.ElementAt(mainToolContext.cameraManager.pageList.Count - 1).selectNum = backNum;
            mainToolContext.cameraManager.pageList.ElementAt(mainToolContext.cameraManager.pageList.Count - 1).fontColor = colorBoxManager.selectItem.colors;
            mainToolContext.cameraManager.pageList.ElementAt(mainToolContext.cameraManager.pageList.Count - 1).isAuto = true;
            mainToolContext.cameraManager.pageList.ElementAt(mainToolContext.cameraManager.pageList.Count - 1).isSet = true;

            for(int i=0; i<mainToolContext.viewPortMgr.ObjectList.Count; i++)
            {
                ViewportObj obj = mainToolContext.viewPortMgr.ObjectList[i];
                int selNum = rand.Next(5);
                while(selNum==backNum)
                {
                    selNum = rand.Next(5);
                }
                Color tcolor = colorBoxManager.selectItem.colors[selNum];
                obj.colorBrush.Color = tcolor;
            }
        }
        private void click_Cancel(object sender, RoutedEventArgs e)
        {
            Close();

        }
       
    }
}
